﻿<%@ Page Title="登录" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="RegexLib.Web.Views.Member.Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="box">
<div class="bt">登录</div>
<div class="bc">
	<form id="LoginForm" action="/Member/LoginSubmit/" method="post">
		<input type="hidden" name="returnUrl" value='<%= ViewData["ReturnUrl"] %>' />
		<table>
		<tr><td>Email：</td><td><input type="text" name="userEmail" class="input" /></td></tr>
		<tr><td>密码：</td><td><input type="password" name="userPassword" class="input" /></td></tr>
		</table>
		<input type="checkbox" name="rememberMe" id="chkRememberMe" /><label for="chkRememberMe">记住我</label>
	</form>
	<button id="SubmitBtn">登录</button>
	<div class="cmd-r">
		<a href="/Member/ChangePassword/">忘记密码</a>
		<a href="/Member/Register/">注册新用户</a>
	</div>
	<p><span id="MsgSpan"></span></p>
</div>
</div>
</asp:Content>
<asp:Content ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
<script type="text/javascript">
var c_LoginForm;
var c_SubmitBtn;
var c_MsgSpan;

function GetElements()
{
	c_LoginForm = YAHOO.util.Dom.get("LoginForm");
	c_SubmitBtn = YAHOO.util.Dom.get("SubmitBtn");
	c_MsgSpan = YAHOO.util.Dom.get("MsgSpan");
}

function LoginFail(o)
{
	c_MsgSpan.className = "err";
	c_MsgSpan.innerText = "连接错误。" + o.statusText;
	c_SubmitBtn.disabled = false;
}

function LoginSuccess(o)
{
	try
	{
		var data = YAHOO.lang.JSON.parse(o.responseText);
		if(data.IsError)
		{
			c_MsgSpan.className = "err";
			c_MsgSpan.innerText = data.Message;
			c_SubmitBtn.disabled = false;
		}
		else
		{
			window.location = data.Message;
		}
	}
	catch(e)
	{
		c_MsgSpan.className = "err";
		c_MsgSpan.innerText = "解析响应时出错。";
	}
}

function DoLogin()
{
	c_SubmitBtn.disabled = true;

	var callback = {success:LoginSuccess,failure:LoginFail,timeout:30000};
	YAHOO.util.Connect.setForm(c_LoginForm);
	YAHOO.util.Connect.asyncRequest("POST", "/Member/LoginSubmit/", callback, null);
}

function init()
{
	GetElements();
	YAHOO.util.Event.addListener(c_SubmitBtn, "click", DoLogin);
}

YAHOO.util.Event.onDOMReady(init);
</script>
</asp:Content>